php if string contains

115

php string contains -

$string = 'The lazy fox jumped over the fence';

if (str_contains($string, 'lazy')) {
    echo "The string 'lazy' was found in the string\n";
}

php if string contains -

$a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}

how to check if a string contains a substring in php -

$a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}

php if string contains -

if (str_contains('How are you', 'are')) { 
    echo 'true';
}

check if string contains character php -

// this method is new with PHP 8 and above
$haystack = "Damn, I wonder if this string contains a comma.";
if (str_contains($haystack, ",")) {
	echo "There is a comma!!";
}

Comments

Submit
0 Comments